Getting into the Mindset
I find that if I read out some reminders on how to think, then I have a better chance at solving algorithms.
Here is a curated list of all the reminders I give myself before going into a problem:
- $\text{you have the sorted sequences } \mathbb{Z} \text { and } \mathbb{R}$
- $\text{counting counts jumps not elements}$
- $\text{you have 2 or more fingers}$
- $\text{know what is changing so you don't over compensate}$
- $\text{process data before processing it again}$
- $\text{if you go "how is this possible?", sort it}$
- $\text{when a sorted sequence is rotated, it is bisected into two sorted sub sequences}$
- $\text{multiply options at each step to get total possiblities}$
Some of these are pretty cryptic so I'll elaborate
You have 2 or more fingers
This is simply a reference to algorithmic pointers or just variables that point to elements in an array. I find this reminder useful because pointers can be used to create many different kinds of passes over arrays. One type of pointer usage is so common that it has it's own name: Sliding Window. This is simply where you initialize 2 pointers in an array that are offset by some fixed amount and incremented together as you pass through the array. This is useful to get a snapshot of a part of an array over the iteration.
If you go "how is this possible?", sort it
This is a bit of a gross exaggeration, but all I mean is that you want to do everything to your array or input that you can before you ask this question. Sometimes the way you change your data first can be unintuitive (like sorting it).